package user;

import java.text.SimpleDateFormat;
import java.util.Date;

public class User {
    private String name;
    private String id;
    private char sex;
    private int age;
    private String password;
    private String phoneNum;

    public User() {
    }

    public User(String name, String id, char sex, int age, String password, String phoneNum) {
        setName(name);
        setSex(sex);
        setAge(age);
        setPassword(password);
        setPhoneNum(phoneNum);
    }

    public void setName(String name) {
        while(true){
            if(name.length() > 1 && name.length() < 40){
                this.name = name;
                return;
            }else{
                System.out.println("名字长度必须大于1，请重新输入");
            }
        }
    }

    public void setId(String id) {
        while(true){
            if(id.length() == 10){
                this.id = id;
                return;
            }else{
                System.out.println("id长度应为11位，请重新输入");
            }
        }
    }

    public void setSex(char sex) {
        while(true){
            if(sex == '男' || sex == '女'){
                this.sex = sex;
                return;
            }else{
                System.out.println("性别只能填男或女，请重新输入");
            }
        }
    }

    public void setAge(int age) {
        while(true){
            if(age > 0 && age < 120){
                this.age = age;
                return;
            }else{
                System.out.println("年龄范围应在1-120之间，请重新填写");
            }
        }
    }

    public void setPassword(String password) {
        while(true){
            if(password.length() >= 6){
                this.password = password;
                return;
            }else{
                System.out.println("密码长度应大于6，请重新输入");
            }
        }
    }

    public void setPhoneNum(String phoneNum) {
        while(true){
            if(phoneNum.length() == 11){
                this.phoneNum = phoneNum;
                return;
            }else{
                System.out.println("手机号长度应为11，请重新输入");
            }
        }

    }

    public String getName() {
        return name;
    }

    public String getId() {
        return id;
    }

    public char getSex() {
        return sex;
    }

    public int getAge() {
        return age;
    }

    public String getPassword() {
        return password;
    }

    public String getPhoneNum() {
        return phoneNum;
    }

    @Override
    public String toString() {
        return "用户\n" +
                "姓名：" + name  +
                "\tid:" + id +
                "\t性别：" + sex +
                "\t年龄：" + age +
                "\t密码：" + password+
                "\t手机号：" + phoneNum;
    }

    //    public String getInfo(){
//        return "姓名：" + getName() + "\tid = " + getId() + "\t性别:" + getSex() + "\t年龄:" +getAge()
//                + "\n密码:" + getPassword() + "\t电话号码:"+getPhoneNum();
//    }
    //    存放注册信息，用于打印
//    public String getInfo() {
//        date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//        String detail = "";
//        detail += "姓名 " + getName() + "\t学号" + getStuNum() + "\t性别 " + getSex() + "年龄" + getAge() +
//                "\n密码" + getPassword() + "\t手机号 " + getPhoneNum() + "\t注册日期" + simpleDateFormat.format(date);
//        return detail;
//    }
}
